# -*- coding: utf-8 -*-

import operator

#7 = 111b 5=101b

def f(ax,ay):
    ret=ax
    for i in range(ax+1,ay+1):
        ret=operator.xor(ret,i)
    return ret

size,query_no=map(int,raw_input().split())
array=map(int,raw_input().split())

dict1=dict()

for i in range(query_no):
    lj,rj=map(int,raw_input().split())
    maxv=0
    for x in range(lj,rj+1):
        for y in range(lj,rj+1):
            if array[x-1]<=array[y-1]:
                #print dict1
                if (array[x-1],array[y-1]) in dict1:
                    maxv=max(maxv,dict1[(array[x-1],array[y-1])])
                else:
                    dict1[(array[x-1],array[y-1])]=f(array[x-1],array[y-1])
                    maxv=max(maxv,dict1[(array[x-1],array[y-1])])
                    
                
    print maxv
            